package com.bjesc_b2c.app.appraiset.mvp.view.activity;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.RequestAndResultCode;
import com.bjesc_b2c.app.appraiset.adapter.SelectColorAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.MultiItemTypeAdapter;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import master_bean.SelectColorBean;

/**
 * Created by Jason Chen on 2017/2/22.
 * 选择颜色
 */

public class SelectColorActivity extends BaseActivity implements MultiItemTypeAdapter.OnItemClickListener {
    @InjectView(R.id.recycler_view)
    RecyclerView recyclerView;

    private SelectColorAdapter colorAdapter;
    private List<SelectColorBean> colorList;
    private String colorName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_selectcolor);
        ButterKnife.inject(this);
        getColorList();
        initViews();
    }

    private void initViews() {
        colorAdapter = new SelectColorAdapter(this, R.layout.layout_item_select_color, colorList);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        recyclerView.setAdapter(colorAdapter);
        colorAdapter.setOnItemClickListener(this);
    }


    public List<SelectColorBean> getColorList() {
        colorList = new ArrayList<>();
        colorList.add(new SelectColorBean("黄色", R.drawable.shape_selector_color_circle_yellow, false));
        colorList.add(new SelectColorBean("红色", R.drawable.shape_selector_color_circle_red, false));
        colorList.add(new SelectColorBean("黑色", R.drawable.shape_selector_color_circle_black, false));
        colorList.add(new SelectColorBean("白色", R.drawable.shape_selector_color_circle_white, false));
        colorList.add(new SelectColorBean("蓝色", R.drawable.shape_selector_color_circle_blue, false));
        colorList.add(new SelectColorBean("绿色", R.drawable.shape_selector_color_circle_green, false));
        colorList.add(new SelectColorBean("紫色", R.drawable.shape_selector_color_circle_violet, false));
        colorList.add(new SelectColorBean("棕色", R.drawable.shape_selector_color_circle_brown, false));
        colorList.add(new SelectColorBean("香槟色", R.drawable.shape_selector_color_circle_champagne, false));
        colorList.add(new SelectColorBean("深灰色", R.drawable.shape_selector_color_circle_darkgrey, false));
        colorList.add(new SelectColorBean("银灰色", R.drawable.shape_selector_color_circle_silvergray, false));
        colorList.add(new SelectColorBean("橙色", R.drawable.shape_selector_color_circle_orange, false));
        colorList.add(new SelectColorBean("其他", R.drawable.shape_selector_color_circle_white, false));
        return colorList;
    }

    @Override
    public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
        for (int i = 0; i < colorList.size(); i++) {
            if (i == position) {
                colorList.get(i).setVisiable(true);
            } else {
                colorList.get(i).setVisiable(false);
            }
        }
        colorName = colorList.get(position).getColorName();
        colorAdapter.notifyDataSetChanged();
        Intent intent = new Intent();
        intent.putExtra("colorName",colorName);
        setResult(RequestAndResultCode.SelectColorActivity_ResultCode,intent);
        finish();
    }

    @Override
    public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
        return false;
    }

    @OnClick({R.id.iv_return, R.id.tv_sure})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_return:
                finish();
                break;
            case R.id.tv_sure:
                Intent intent = new Intent();
                intent.putExtra("colorName",colorName);
                setResult(RequestAndResultCode.SelectColorActivity_ResultCode,intent);
                finish();
                break;
        }
    }
}
